import ccxt

# exchange = ccxt.okex3()  # default id
# okcoin1 = ccxt.okex3({'id': 'okex3a'})
# okcoin2 = ccxt.okex3({'id': 'okex3b'})
# id = 'okex'
# chinaokex3 = eval('ccxt.%s ()' % id)
# print(chinaokex3)
# # gdax = getattr(ccxt, 'OKEX')()
# # print(gdax)
#
#
# api_key = "217078fb-bb7e-47a6-be2d-10c81b22a645"
# secret_key = "571543CA73D1970C5A81380D93D9AB0A"
# passphrase = "guavaguava"
# config = {'urls': {'api': 'https://www.okex.cc'},
#           'apiKey': api_key,
#           'secret': secret_key,
#           'nonce': passphrase
#           }
# # from variable id
# exchange_id = 'okex3'
# exchange_class = getattr(ccxt, exchange_id)
# print(exchange_class)
# exchange = exchange_class({
#     'apiKey': api_key,
#     'secret': secret_key,
#     'timeout': 500,
#     'enableRateLimit': True,
# })
#

# document
# http://blog.hubwiz.com/2019/10/18/ccxt-dev-manual/

api_key = "60f4d9ee-188e-4ee8-9672-a7d8e37a40cc"
secret_key = "D1922151CCD13FB3CAAF59868A50F7B7"
passphrase = "guavaguava"
exchange = ccxt.okex3({
    'apiKey': api_key,
    'secret': secret_key,
    'password': passphrase,
    'timeout': 30000,
    'enableRateLimit': True,
    'passphrase': passphrase
})

exchange.hostname = 'ouyi.cc'
symbol='ETH-USDT-SWAP'
print(exchange.options)
print(exchange.id, exchange.hostname)
# markets = exchange.load_markets()
# # print(okcoin1.id, markets)
# for item in markets:
#     print(item)
#     # (ETH-USDT-SWAP)

import time

# get bids and asks
# print(exchange.fetch_order_book('ETH-USDT-SWAP'))


# limit = 20
# level20=exchange.fetch_order_book('ETH-USDT-SWAP', limit)
# print(level20)

# list api
# methodsList=dir(ccxt.okex3())
# for item in methodsList:
#     print(item)

#获取账号信息
# print(exchange.fetchBalance())
# balance={'info': [{'frozen': '0', 'hold': '0', 'id': '', 'currency': 'BTC', 'balance': '0.00000539', 'available': '0.00000539', 'holds': '0'}, {'frozen': '0', 'hold': '0', 'id': '', 'currency': 'TORN', 'balance': '0.000000644', 'available': '0.000000644', 'holds': '0'}, {'frozen': '0', 'hold': '0', 'id': '', 'currency': 'USDT', 'balance': '0.0000000068174', 'available': '0.0000000068174', 'holds': '0'}], 'timestamp': None, 'datetime': None, 'BTC': {'free': 5.39e-06, 'used': 0.0, 'total': 5.39e-06}, 'TORN': {'free': 6.44e-07, 'used': 0.0, 'total': 6.44e-07}, 'USDT': {'free': 6.8174e-09, 'used': 0.0, 'total': 6.8174e-09}, 'free': {'BTC': 5.39e-06, 'TORN': 6.44e-07, 'USDT': 6.8174e-09}, 'used': {'BTC': 0.0, 'TORN': 0.0, 'USDT': 0.0}, 'total': {'BTC': 5.39e-06, 'TORN': 6.44e-07, 'USDT': 6.8174e-09}}
# for item in balance['info']:
#     print(item)

# 获取 ohlcv
# result= exchange.fetch_ohlcv (symbol, '3m',limit=3000)
# print(result)
result=[[1628640900000, 3159.99, 3171.63, 3158.29, 3167.08, 3433.0], [1628641080000, 3167.16, 3168.0, 3159.0, 3159.28, 1740.1], [1628641260000, 3159.29, 3159.91, 3140.61, 3144.31, 3062.6], [1628641440000, 3144.31, 3147.22, 3141.36, 3143.37, 997.0], [1628641620000, 3143.63, 3158.69, 3143.36, 3151.07, 2035.7], [1628641800000, 3151.07, 3167.95, 3151.07, 3162.88, 2540.3], [1628641980000, 3162.89, 3168.0, 3155.03, 3155.29, 1674.9], [1628642160000, 3155.29, 3159.73, 3151.5, 3153.7, 1500.1], [1628642340000, 3153.71, 3161.82, 3153.71, 3161.81, 1139.6], [1628642520000, 3161.81, 3165.66, 3156.41, 3159.69, 1278.9], [1628642700000, 3159.69, 3168.0, 3158.48, 3166.38, 1282.9], [1628642880000, 3166.39, 3170.0, 3159.4, 3162.62, 1202.2], [1628643060000, 3163.0, 3168.13, 3160.42, 3164.0, 713.7], [1628643240000, 3164.11, 3166.71, 3161.28, 3163.29, 581.9], [1628643420000, 3163.3, 3170.0, 3163.3, 3169.18, 1362.7], [1628643600000, 3169.17, 3174.88, 3159.08, 3162.0, 2510.2], [1628643780000, 3161.45, 3162.09, 3158.28, 3160.0, 596.3], [1628643960000, 3161.0, 3161.28, 3158.4, 3160.0, 420.9], [1628644140000, 3160.0, 3165.99, 3159.44, 3163.01, 661.1], [1628644320000, 3163.89, 3173.04, 3163.1, 3166.51, 1214.6], [1628644500000, 3166.51, 3175.0, 3166.08, 3171.36, 2149.0], [1628644680000, 3171.36, 3173.79, 3168.9, 3173.12, 944.7], [1628644860000, 3173.13, 3181.0, 3172.91, 3175.0, 2812.5], [1628645040000, 3175.01, 3182.0, 3175.01, 3181.0, 1581.9], [1628645220000, 3180.99, 3184.11, 3176.1, 3181.0, 1781.5], [1628645400000, 3181.5, 3187.88, 3181.5, 3184.59, 2794.2], [1628645580000, 3184.59, 3184.59, 3172.07, 3173.34, 1617.0], [1628645760000, 3173.86, 3175.0, 3170.0, 3170.79, 931.3], [1628645940000, 3170.79, 3172.45, 3165.12, 3170.1, 1328.4], [1628646120000, 3170.1, 3174.69, 3170.1, 3171.54, 542.2], [1628646300000, 3170.28, 3170.29, 3163.45, 3164.71, 1159.8], [1628646480000, 3164.72, 3172.44, 3164.55, 3171.51, 1274.2], [1628646660000, 3171.5, 3175.0, 3168.63, 3174.49, 594.8], [1628646840000, 3173.7, 3175.95, 3169.4, 3169.55, 420.8], [1628647020000, 3169.56, 3171.78, 3167.82, 3171.78, 705.4], [1628647200000, 3171.77, 3182.0, 3171.77, 3181.31, 2090.6], [1628647380000, 3181.32, 3182.3, 3169.89, 3170.98, 1806.1], [1628647560000, 3170.97, 3182.18, 3170.97, 3178.82, 2753.4], [1628647740000, 3178.82, 3180.04, 3172.83, 3174.48, 669.4], [1628647920000, 3174.23, 3176.77, 3172.49, 3172.49, 288.3], [1628648100000, 3172.27, 3179.89, 3169.3, 3169.3, 1465.4], [1628648280000, 3169.01, 3174.3, 3167.25, 3167.64, 931.4], [1628648460000, 3167.64, 3171.17, 3165.0, 3170.39, 1311.7], [1628648640000, 3170.87, 3170.87, 3165.09, 3166.0, 445.4], [1628648820000, 3166.01, 3167.16, 3156.51, 3160.68, 4177.6], [1628649000000, 3160.69, 3161.56, 3147.68, 3148.32, 3479.5], [1628649180000, 3148.32, 3148.41, 3141.28, 3145.74, 5816.7], [1628649360000, 3145.75, 3145.75, 3140.7, 3142.65, 1734.5], [1628649540000, 3142.64, 3145.61, 3130.45, 3131.58, 4490.7], [1628649720000, 3131.66, 3137.12, 3125.5, 3130.88, 4345.1], [1628649900000, 3130.88, 3134.44, 3118.88, 3120.33, 5554.6], [1628650080000, 3120.32, 3133.73, 3120.32, 3133.73, 2488.9], [1628650260000, 3133.73, 3135.89, 3129.22, 3135.89, 1752.6], [1628650440000, 3135.89, 3138.0, 3130.22, 3130.23, 1261.8], [1628650620000, 3130.23, 3137.6, 3130.23, 3136.83, 1439.1], [1628650800000, 3136.82, 3136.82, 3130.0, 3130.89, 1299.8], [1628650980000, 3130.88, 3136.51, 3128.23, 3136.51, 1395.7], [1628651160000, 3136.52, 3136.62, 3132.56, 3133.55, 397.2], [1628651340000, 3132.78, 3134.95, 3132.78, 3133.35, 605.6], [1628651520000, 3133.35, 3137.59, 3133.0, 3137.2, 737.8], [1628651700000, 3137.2, 3148.11, 3136.51, 3148.01, 2310.1], [1628651880000, 3148.01, 3148.01, 3144.14, 3146.0, 1068.5], [1628652060000, 3146.0, 3151.57, 3145.86, 3146.81, 2029.3], [1628652240000, 3146.81, 3153.3, 3146.18, 3147.12, 3008.3], [1628652420000, 3147.12, 3148.4, 3145.48, 3145.48, 684.5], [1628652600000, 3145.48, 3152.0, 3145.47, 3151.54, 731.0], [1628652780000, 3151.54, 3153.0, 3150.65, 3152.84, 1086.0], [1628652960000, 3152.84, 3154.0, 3149.18, 3149.19, 1511.7], [1628653140000, 3149.19, 3150.05, 3146.69, 3146.69, 627.7], [1628653320000, 3146.69, 3148.34, 3141.6, 3147.9, 2149.3], [1628653500000, 3148.22, 3152.94, 3148.22, 3152.51, 1106.6], [1628653680000, 3152.51, 3154.8, 3152.29, 3154.8, 910.0], [1628653860000, 3154.8, 3158.88, 3154.41, 3158.5, 1398.1], [1628654040000, 3158.49, 3158.5, 3154.25, 3156.06, 748.4], [1628654220000, 3156.64, 3159.8, 3155.67, 3157.74, 911.8], [1628654400000, 3157.73, 3160.9, 3153.97, 3157.56, 1917.6], [1628654580000, 3157.56, 3164.78, 3157.56, 3163.47, 1435.0], [1628654760000, 3164.02, 3166.78, 3161.27, 3165.96, 1195.4], [1628654940000, 3165.97, 3173.03, 3163.71, 3163.86, 6014.8], [1628655120000, 3163.87, 3165.89, 3161.6, 3165.89, 1240.1], [1628655300000, 3165.89, 3168.9, 3164.08, 3165.87, 1464.3], [1628655480000, 3165.87, 3166.38, 3159.27, 3166.38, 1250.4], [1628655660000, 3166.38, 3166.53, 3161.12, 3165.85, 1163.1], [1628655840000, 3165.85, 3166.67, 3163.52, 3165.06, 777.6], [1628656020000, 3165.06, 3167.95, 3161.8, 3167.92, 533.5], [1628656200000, 3167.91, 3168.8, 3161.93, 3163.33, 931.7], [1628656380000, 3163.51, 3165.14, 3158.17, 3158.18, 1096.0], [1628656560000, 3158.17, 3158.18, 3144.59, 3150.71, 4026.0], [1628656740000, 3150.7, 3159.87, 3150.7, 3158.58, 1975.4], [1628656920000, 3158.58, 3164.77, 3158.57, 3163.97, 1623.3], [1628657100000, 3163.96, 3176.52, 3163.62, 3174.67, 4934.9], [1628657280000, 3174.66, 3174.67, 3166.21, 3172.44, 1754.0], [1628657460000, 3172.01, 3174.57, 3167.92, 3168.21, 1336.7], [1628657640000, 3168.2, 3169.25, 3164.6, 3164.82, 915.6], [1628657820000, 3164.82, 3166.01, 3161.93, 3165.29, 1087.9], [1628658000000, 3165.29, 3171.2, 3165.29, 3168.14, 1243.5], [1628658180000, 3168.14, 3170.34, 3166.59, 3166.6, 702.3], [1628658360000, 3166.59, 3166.6, 3159.13, 3163.89, 1603.0], [1628658540000, 3163.27, 3163.99, 3161.03, 3161.05, 813.1], [1628658720000, 3161.04, 3161.07, 3158.56, 3158.57, 862.4], [1628658900000, 3158.56, 3158.57, 3152.54, 3158.56, 1939.6], [1628659080000, 3158.57, 3162.15, 3156.85, 3159.0, 1365.7], [1628659260000, 3159.74, 3163.71, 3156.07, 3163.71, 760.6], [1628659440000, 3163.71, 3175.0, 3163.7, 3173.39, 3085.0], [1628659620000, 3173.39, 3173.4, 3166.02, 3168.43, 721.6], [1628659800000, 3168.92, 3173.61, 3167.0, 3172.14, 1000.5], [1628659980000, 3172.15, 3174.0, 3171.48, 3172.35, 991.2], [1628660160000, 3172.34, 3177.63, 3171.57, 3176.96, 2456.9], [1628660340000, 3176.95, 3179.95, 3175.01, 3177.6, 2605.1], [1628660520000, 3177.49, 3180.99, 3175.24, 3177.06, 2543.4], [1628660700000, 3177.41, 3184.26, 3175.08, 3176.34, 2639.4], [1628660880000, 3176.34, 3179.4, 3175.02, 3179.4, 1391.1], [1628661060000, 3179.39, 3183.87, 3178.89, 3180.25, 1462.9], [1628661240000, 3180.24, 3180.25, 3172.83, 3173.68, 1351.6], [1628661420000, 3173.69, 3179.51, 3172.39, 3176.93, 1252.5], [1628661600000, 3177.06, 3187.12, 3177.05, 3184.0, 3533.6], [1628661780000, 3184.01, 3184.91, 3181.0, 3181.52, 1249.4], [1628661960000, 3181.52, 3181.71, 3178.01, 3179.63, 1021.4], [1628662140000, 3179.98, 3180.92, 3174.44, 3175.51, 1567.6], [1628662320000, 3175.51, 3178.85, 3174.67, 3176.68, 1175.6], [1628662500000, 3176.68, 3176.68, 3168.78, 3174.91, 1628.1], [1628662680000, 3173.77, 3181.0, 3173.47, 3181.0, 1301.7], [1628662860000, 3181.0, 3187.46, 3178.47, 3187.3, 2491.3], [1628663040000, 3187.3, 3215.0, 3187.3, 3210.13, 17160.4], [1628663220000, 3210.12, 3218.6, 3198.14, 3203.45, 8008.6], [1628663400000, 3203.45, 3215.8, 3203.44, 3213.26, 5099.6], [1628663580000, 3213.26, 3219.49, 3212.93, 3219.03, 3528.7], [1628663760000, 3219.02, 3219.87, 3209.24, 3211.39, 4018.9], [1628663940000, 3211.0, 3211.08, 3150.0, 3173.72, 11538.2], [1628664120000, 3172.56, 3174.78, 3151.32, 3172.4, 21494.7], [1628664300000, 3172.41, 3174.24, 3157.44, 3165.97, 6724.9], [1628664480000, 3166.0, 3186.42, 3166.0, 3181.99, 4920.4], [1628664660000, 3182.0, 3192.91, 3178.06, 3192.47, 5246.5], [1628664840000, 3192.98, 3209.7, 3192.96, 3196.18, 11298.7], [1628665020000, 3196.18, 3201.73, 3190.62, 3197.19, 3173.3], [1628665200000, 3197.19, 3214.95, 3197.19, 3212.0, 6380.8], [1628665380000, 3212.0, 3249.66, 3205.71, 3242.9, 22265.7], [1628665560000, 3242.91, 3252.87, 3228.95, 3238.84, 10489.1], [1628665740000, 3238.84, 3244.0, 3232.49, 3236.06, 4286.0], [1628665920000, 3236.06, 3242.75, 3235.34, 3240.39, 3233.7], [1628666100000, 3240.38, 3250.03, 3239.03, 3239.87, 5247.1], [1628666280000, 3239.64, 3245.57, 3230.22, 3230.23, 4230.6], [1628666460000, 3230.24, 3236.42, 3225.82, 3230.29, 3354.3], [1628666640000, 3230.35, 3235.0, 3224.0, 3233.92, 2997.4], [1628666820000, 3233.92, 3235.0, 3228.12, 3233.33, 2171.5], [1628667000000, 3233.97, 3234.74, 3223.2, 3224.1, 2115.8], [1628667180000, 3224.76, 3229.9, 3219.49, 3229.89, 2449.8], [1628667360000, 3229.88, 3229.88, 3221.56, 3224.11, 1306.6], [1628667540000, 3224.12, 3224.75, 3216.74, 3221.99, 5268.1], [1628667720000, 3222.0, 3226.89, 3221.0, 3221.47, 1214.1], [1628667900000, 3221.46, 3235.96, 3221.46, 3234.79, 2607.7], [1628668080000, 3234.79, 3234.79, 3206.12, 3212.0, 5548.5], [1628668260000, 3212.01, 3221.0, 3210.52, 3221.0, 4083.1], [1628668440000, 3221.0, 3235.19, 3220.07, 3235.19, 3485.4], [1628668620000, 3235.18, 3235.19, 3225.25, 3230.9, 2243.9], [1628668800000, 3231.0, 3243.6, 3226.44, 3229.36, 6926.4], [1628668980000, 3229.36, 3241.96, 3228.89, 3234.79, 3526.5], [1628669160000, 3234.78, 3236.13, 3222.88, 3228.41, 3384.2], [1628669340000, 3228.41, 3229.76, 3217.5, 3220.26, 2232.7], [1628669520000, 3220.5, 3224.97, 3215.0, 3219.56, 2801.9], [1628669700000, 3219.31, 3222.87, 3214.11, 3218.0, 3665.4], [1628669880000, 3218.0, 3219.8, 3207.01, 3217.53, 3425.6], [1628670060000, 3217.53, 3217.53, 3205.02, 3208.67, 2308.3], [1628670240000, 3208.67, 3217.42, 3204.35, 3216.84, 2851.2], [1628670420000, 3216.85, 3223.14, 3216.23, 3220.65, 2103.3], [1628670600000, 3220.64, 3223.61, 3208.9, 3209.06, 2561.1], [1628670780000, 3209.06, 3215.0, 3206.59, 3213.15, 2345.7], [1628670960000, 3213.15, 3215.77, 3208.91, 3210.93, 722.9], [1628671140000, 3210.56, 3211.97, 3206.6, 3207.12, 1132.6], [1628671320000, 3207.66, 3213.0, 3207.11, 3211.99, 1035.9], [1628671500000, 3211.98, 3218.0, 3207.05, 3216.31, 1852.0], [1628671680000, 3216.32, 3218.0, 3213.01, 3213.61, 798.0], [1628671860000, 3213.27, 3214.49, 3208.0, 3213.66, 932.4], [1628672040000, 3213.66, 3221.0, 3213.32, 3216.0, 1634.2], [1628672220000, 3216.0, 3219.0, 3214.84, 3216.7, 1042.3], [1628672400000, 3216.69, 3227.84, 3216.21, 3222.77, 2233.6], [1628672580000, 3223.25, 3226.8, 3220.0, 3220.0, 1312.8], [1628672760000, 3220.0, 3222.32, 3218.17, 3221.73, 743.2], [1628672940000, 3221.73, 3223.58, 3214.28, 3214.28, 1505.7], [1628673120000, 3214.28, 3220.0, 3214.0, 3214.0, 1576.5], [1628673300000, 3214.01, 3215.72, 3206.88, 3207.07, 2228.0], [1628673480000, 3207.35, 3215.75, 3206.69, 3215.01, 2263.4], [1628673660000, 3215.0, 3215.51, 3210.0, 3214.6, 613.0], [1628673840000, 3214.59, 3223.67, 3214.59, 3220.85, 3222.8], [1628674020000, 3220.2, 3225.6, 3220.2, 3224.24, 1432.2], [1628674200000, 3224.0, 3225.8, 3221.28, 3222.83, 803.0], [1628674380000, 3222.35, 3228.0, 3219.14, 3227.99, 1182.4], [1628674560000, 3227.98, 3233.06, 3225.46, 3229.8, 2733.5], [1628674740000, 3229.8, 3230.43, 3222.2, 3222.94, 1135.4], [1628674920000, 3222.94, 3231.0, 3222.28, 3229.75, 1060.3], [1628675100000, 3229.76, 3234.85, 3224.03, 3225.0, 2189.6], [1628675280000, 3224.99, 3228.8, 3224.12, 3228.62, 1086.9], [1628675460000, 3228.62, 3233.8, 3225.0, 3225.72, 1609.8], [1628675640000, 3225.71, 3229.89, 3225.0, 3227.0, 1314.9], [1628675820000, 3227.01, 3227.01, 3223.5, 3224.99, 1220.6], [1628676000000, 3224.98, 3228.09, 3223.57, 3226.17, 1493.0], [1628676180000, 3226.17, 3227.0, 3222.0, 3222.0, 600.3], [1628676360000, 3222.01, 3223.81, 3216.18, 3223.81, 2906.0], [1628676540000, 3224.33, 3224.33, 3221.25, 3223.99, 409.7], [1628676720000, 3223.99, 3231.34, 3223.99, 3229.38, 2739.7]]
# for item in result:
#     print(item)
print(len(result))
